package chapter15;

import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-26 下午3:50
 */
public class TestDemo {
    public static void main(String[] args) {
        IEmpService service = ServiceFactory.getEmpService();

        int empno = new Random().nextInt(1000);
        Emp emp = new Emp();
        emp.setEmpName("test");
        emp.setEmpno(empno);
        emp.setHireDate(new Date());
        emp.setComm(new Random().nextDouble() * 1000);
        emp.setJob("sale");
        emp.setSal(new Random().nextDouble() * 1000);

        service.save(emp);

        List<Emp> list = service.getAllEmp();
        list.forEach(System.out::println);

        Emp newMem = service.getEmpById(empno);
        System.out.println("id:" + empno + " info:" + newMem.toString());

        emp.setJob("manager");
        service.updateEmp(emp);
        newMem = service.getEmpById(empno);
        System.out.println("id:" + empno + " info:" + newMem.toString());

        boolean r = service.delEmp(empno);
        System.out.println("del emp id:" + empno + "?" + r);

        boolean flag = service.getEmpById(empno) != null;
        System.out.println("find emp id:" + empno + "?" + flag);
    }
}
